﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Edit.aspx.cs" Inherits="CRM.Web.Admin.Page.TextInfo.Edit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <link href="/Content/jquery/uploadify/uploadify.css" rel="stylesheet" type="text/css" />
    <script src="/Content/jquery/jquery-1.4.1.js" type="text/javascript"></script>
    <link href="/Content/jquery/validation/validation.css" rel="stylesheet" type="text/css" />
    <script src="/Content/jquery/validation/validation.js" type="text/javascript"></script>
    <script src="/Content/jquery/artDialog/jquery.artDialog.source.js?skin=default" type="text/javascript"></script>
    <script src="/Content/jquery/artDialog/plugins/iframeTools.source.js?skin=default"
        type="text/javascript"></script>
    <script src="/Content/jquery/query_url.js" type="text/javascript"></script>
    <script src="/Content/jquery/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script src="/Content/jquery/kindeditor/kindeditor.js" type="text/javascript"></script>
    <script src="/Content/jquery/uploadify/jquery.uploadify.v2.1.4.js" type="text/javascript"></script>
    <script src="/Content/jquery/uploadify/swfobject.js" type="text/javascript"></script>
    <script type="text/javascript">

        var editor;

        //页面呈现后再次默认初始化
        window.onload = function () {
            //默认初始化
            _cnblogs_yixian_edit._initFunc();

            //默认加载第一条
            _cnblogs_yixian_edit._getSingleFunc();
        }

        $(document).ready(function () {
            //内容块名称
            $('#TextKey').blur(function () {
                ValidationInput($(this),
undefined,
undefined,
undefined
);
            }).focus(function () {
                ClearErrorMessage($(this));
            });
            //显示内容
            $('#TextValue').blur(function () {
                ValidationInput($(this),
undefined,
undefined,
undefined
);
            }).focus(function () {
                ClearErrorMessage($(this));
            });
            KindEditor.ready(function (K) {
                editor = K.create('#TextValue', {
                    resizeType: 1,
                    allowPreviewEmoticons: false,
                    allowImageUpload: true,
                    items: [
'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
'insertunorderedlist', '|', 'emoticons', 'image', 'link', '|', 'source'],
                    afterBlur: function () {
                        $('#TextValue').val(editor.text()).trigger('blur');
                    },
                    afterFocus: function () {
                        ClearErrorMessage($('#TextValue'));
                    }
                });
            });

        });

        var _cnblogs_yixian_edit = {

            //单一实体
            _single: {},

            //主键ID
            _id: "",

            //初始化函数
            _initFunc: function () {
                _cnblogs_yixian_edit._id = $.query.get("TextId");
            },

            //获取单一实体
            _getSingleFunc: function () {
                $.ajax({
                    type: "post",
                    data: {
                        action: "SingleFunc",
                        TextId: _cnblogs_yixian_edit._id
                    },
                    url: "/Ajax/TextInfoAjax.ashx",
                    beforeSend: function () {
                    },
                    success: function (data) {
                        if (data != "") {
                            var json = $.parseJSON(data);

                            _cnblogs_yixian_edit._single = json;

                            $('#TextKey').val(json.TextKey);
                            $('#TextValue').val(json.TextValue);
                            editor.html($('#TextValue').val());

                        } else {
                            $.dialog.alert("获取数据失败！");
                        }
                    },
                    complete: function () {
                    },
                    error: function () {
                        $.dialog.alert("获取数据异常！");
                    }
                });
            },

            //提交表单
            _submitFunc: function ($this) {
                var load = "";
                var isSuccess = true;

                //需要验证的数组
                var validationArray = [
                  { TextKey: "" },
                                  { TextValue: "" }
                ];

                //可空判断
                var result = SubmitForm(validationArray, true);

                //判断是否验证通过
                if (!result)
                    return isSuccess = false;

                //给实体赋值
                _cnblogs_yixian_edit._single.TextKey = $.trim($("#TextKey").val());
                _cnblogs_yixian_edit._single.TextValue = editor.html(); 

                $.ajax({
                    type: "post",
                    data: {
                        action: "EditFunc",
                        json: JSON.stringify(_cnblogs_yixian_edit._single)
                    },
                    url: "/Ajax/TextInfoAjax.ashx",
                    async: false,
                    beforeSend: function () {
                        //load = $.dialog({ title: false, cancel: false });
                    },
                    success: function (data) {
                        if (data == "True") {
                            isSuccess = true;
                        } else {
                            isSuccess = false;
                        }
                    },
                    complete: function () {
                        load.close();
                    },
                    error: function () {
                        isSuccess = false;
                    }
                });
                return isSuccess;
            }
        };

    </script>
</head>
<body style="text-align: left; font-size: 12px">
    <table>
        <tr>
            <td>
                内容块名称:
            </td>
            <td>
                <input type="text" readonly="readonly" id="TextKey" style="width:200px;" />
            </td>
        </tr>
        <tr>
            <td>
                显示内容:
            </td>
            <td>
                <textarea id='TextValue' style="width:500px;height:390px;"></textarea>
            </td>
        </tr>
    </table>
</body>
</html>
